package com.lanou.dllo.soccernews.fragment.homelinefragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou.dllo.soccernews.R;
import com.lanou.dllo.soccernews.volley.VolleySingleton;


/**
 * Created by dllo on 15/10/21.
 */
public class RecommendFragment extends Fragment {
    private ImageView imageView;
    private TextView titleTV;
    private String title,imgUrl;



   // private RequestQueue queue;

    //单例模式,整个应用中保证只有一个实例对象  且必须是通过静态方法获取
    ///
    public   RecommendFragment(){}


    public static  RecommendFragment getInstance(String title,String imgUrl) {
        // TODO Auto-generated method stub

        RecommendFragment recommendFragment = new RecommendFragment();
        //传递参数
        Bundle args = new Bundle();
        args.putString("title", title);
        args.putString("imgUrl", imgUrl);
        recommendFragment.setArguments(args);
       return  recommendFragment;
    }

    @Override
    public void onAttach(Context activity) {
        // TODO Auto-generated method stub
        super.onAttach(activity);
        //初始化请求队列
        //queue = Volley.newRequestQueue(activity);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null){
            title = bundle.getString("title");
            imgUrl = bundle.getString("imgUrl");

        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_recommend,container,false);

        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        titleTV = (TextView) view.findViewById(R.id.titleTv);
        imageView = (ImageView) view.findViewById(R.id.imgIV);



    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //获取title信息
        titleTV.setText(title);
        //获取图片信息
     //   Log.i("lanou", imgUrl + "\nhohiohoh");
       // GetVolleyDatasUtil.getBitmapRequest(imgUrl,imageView);
        ImageLoader imageLoader = VolleySingleton.getInstance().getImageLoader();
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(imageView,0,0);
        imageLoader.get(imgUrl,listener);


    }
}
